using Moq;
using NUnit.Framework;
using Tycho.Parser.Peg;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class PrecedenceSpecification {
        [Test]
        public void IfSameProductionAndNotLeftRecursiveThenNotGreater () {
            var production = new Mock<IProduction> ().Object;
            var context = new Mock<IProduction> ().Object;
            var prec1 = new Precedence (production, 0, context);
            var prec2 = new Precedence (production, 0, context);

            Assert.False (prec1.IsGreaterThan (prec2));
        }

        [Test]
        public void IfSameProductionAndLeftRecursiveThenNotGreater () {
            var production = new Mock<IProduction> ();
            production.Setup (p => p.IsLeftRecursive).Returns (true);

            var context = new Mock<IProduction> ().Object;
            var prec1 = new Precedence (production.Object, 0, context);
            var prec2 = new Precedence (production.Object, 0, context);

            Assert.True (prec1.IsGreaterThan (prec2));
        }

        [Test]
        public void IfNotSameProductionAndSameContextButHigherPrecedenceThenGreater () {
            var context = new Mock<IProduction> ().Object;
            var prec1 = new Precedence (new Mock<IProduction> ().Object, 0, context);
            var prec2 = new Precedence (new Mock<IProduction> ().Object, 2, context);

            Assert.True (prec1.IsGreaterThan (prec2));
        }

        [Test]
        public void IfNotSameProductionAndSameContextButLowerPrecedenceThenNotGreater () {
            var context = new Mock<IProduction> ().Object;
            var prec1 = new Precedence (new Mock<IProduction> ().Object, 2, context);
            var prec2 = new Precedence (new Mock<IProduction> ().Object, 0, context);

            Assert.False (prec1.IsGreaterThan (prec2));
        }

        [Test]
        public void IfNotSameProductionAndNotSameContextThenNotGreater () {
            var prec1 = new Precedence (new Mock<IProduction> ().Object, 0, new Mock<IProduction> ().Object);
            var prec2 = new Precedence (new Mock<IProduction> ().Object, 2, new Mock<IProduction> ().Object);

            Assert.False (prec1.IsGreaterThan (prec2));
        }
    }
}